package com.cet.algorithm.贪心算法.摆动序列;

/**
 * @program: cet-practice
 * @description: 摆动序列
 * @author: 陈恩涛
 * @create: 2023-06-05 22:19
 **/
public class LC367 {

    public int wiggleMaxLength(int[] nums) {

        int vector = 0;

        int result = 0;

        for (int i = 0; i < nums.length; i++) {
            if (i == 0) {
                result++;
            } else {
                if (nums[i] == nums[i - 1]) {
                    continue;
                } else if (nums[i] > nums[i - 1]) {
                    if (vector > 0) {
                        continue;
                    }
                    vector = 1;
                    result++;
                } else {
                    if (vector < 0) {
                        continue;
                    }
                    vector = -1;
                    result++;
                }
            }
        }

        return result;
    }

    public static void main(String[] args) {
        LC367 lc367 = new LC367();
        System.out.println(lc367.wiggleMaxLength(new int[]{1, 2, 2, 2, 1}));
    }
}
